//
// @Auther: by wujehy 
// @Email:wujehy@qq.com
// @Data:20-4-20
// @Time:上午11:46
//

#include "Common.h"


const std::string HexCode = "0123456789ABCDEF";

std::string GeeJoan::Common::StringToHex(const std::string &data)
{
    std::string result;
    uint8_t currTemp = 0;
    for (int i = 0; i < data.size(); ++i)
    {
        currTemp = data[i] & 0xff;
        result.push_back( HexCode[currTemp >> 4] );
        result.push_back( HexCode[currTemp & 0x0f] );
    }
    return result;
}

std::string GeeJoan::Common::HexToString(const std::string &data)
{
    std::string result;
    for (int i = 0; i < data.length(); i += 2)
    {
        std::string byte = data.substr( i, 2 );
        char chr = (char) strtol( byte.c_str(), NULL, 16 );
        result.push_back( chr );
    }
    return result;
}


